//
//  PrefixHeader.swift
//  halikaPeso
//
//  Created by L-zh on 2024/12/16.
//

import UIKit

//屏幕的宽度
public let APPWidth = UIScreen.appWidth()
//屏幕的高度
public let APPHeight = UIScreen.appHeight()

public let APPNavHeight = navHeight()

public let APPBottomHeight = bottomHeight()

public  let LLLoadingMessage:String = "加载中..."

public  let LLLoadErrorMessage:String = "加载失败,请重试"


public let AppBlueColor = UIColor.hexcolor(withHex: 0x3d9bfa)

public let AppRedColor = UIColor.hexcolor(withHex: 0xfa3d3d)

public let AppLightblueColor = UIColor.hexcolor(withHex: 0xbce0f5)

public let AppText33Color = UIColor.hexcolor(withHex: 0x333333)

public let AppText66Color = UIColor.hexcolor(withHex: 0x666666)

public let AppText99Color = UIColor.hexcolor(withHex: 0x999999)

public let AppTextCCColor = UIColor.hexcolor(withHex: 0xcccccc)

public let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String

public let appIDFV = UIDevice.current.identifierForVendor?.uuidString ?? "Unable to get IDFV"

public let appSystemVersion = UIDevice.current.systemVersion

public let  LLLoginOutNotification = Notification.Name(rawValue: "LLLoginOutNotification")

public let userSavePath:NSString = ((NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask,true).last!) as NSString).appendingPathComponent("user.data") as NSString
//根据屏幕宽度比例 进行缩放
public func APPScale(f:CGFloat) -> CGFloat {
    
    return (APPWidth / 750.0) * 2 * f
}
//系统字体
public func APPFont(f:CGFloat) -> UIFont {
    return UIFont.systemFont(ofSize: APPScale(f: f ))
}
//HexColor
public func APPHexColor(hexValue:Int32) ->UIColor {
    return UIColor.hexcolor(withHex: UInt32(hexValue))
}
//RGBColor
public func APPRGBColor(r:CGFloat,g:CGFloat,b:CGFloat) -> UIColor {
    
    return UIColor.rgbcolor(withRed: UInt8(r), green: UInt8(g), blue: UInt8(b))
}
//RGBColor
public func APPRandomColor() -> UIColor {
    
    return UIColor.randomColor()
}

func IS_iPhoneXScreen() -> Bool {
    
    guard #available(iOS 11.0, *) else {
        return false
    }
    
    return UIApplication.shared.windows[0].safeAreaInsets != UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0)
}

let IS_IPHONE_X =  IS_iPhoneXScreen()

func navHeight() -> CGFloat {
    
    //导航栏高度也可以根据UINavigationController动态获取
    var navh: Float = 44.0
    
    if #available(iOS 12.0, *) {
        navh += Float((UIApplication.shared.delegate?.window?!.safeAreaInsets.top)!)
    }else if IS_IPHONE_X {
        if #available(iOS 11.0, *) {
            navh += Float((UIApplication.shared.delegate?.window?!.safeAreaInsets.top)!)
        } else {
            // Fallback on earlier versions
        }
    }else{
        navh += Float(UIApplication.shared.statusBarFrame.size.height)
    }
    return CGFloat(navh)
}
func bottomHeight() -> CGFloat {
    var navh: Float = 0.0
    
    if #available(iOS 11.0, *) {
        navh += Float((UIApplication.shared.delegate?.window?!.safeAreaInsets.bottom)!)
    }else{
        navh += 0
    }
    return CGFloat(navh)
}
/// UserDefaults
public let APPUserDefaults:UserDefaults =  UserDefaults.standard

//确定弹框
public func APPConfirmAlertVC(message:String ,completion: @escaping ()->()) {
    let optionMenu = UIAlertController(title: "温馨提示", message: message, preferredStyle: .alert)
    let confirmAction = UIAlertAction(title: "确定", style: .destructive) { (_) in
        completion()
    }
    let cancale = UIAlertAction(title: "取消", style: .cancel, handler: nil)
    
    optionMenu.addAction(cancale)
    optionMenu.addAction(confirmAction)
  UIApplication.shared.delegate?.window??.rootViewController?.present(optionMenu, animated: true, completion: nil)
    
}

public func StringIsEmpty(value: String?) -> Bool {
    
    if value == nil {
        return true
    }
    if let value  = value {
        //然后对String做判断
        return value == "" || value == "(null)" || 0 == value.count
    }else{
        //字符串都不是，直接认为是空串
        return true
    }
}


